package com.example.home.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.AttributeSet
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.base.BaseActivity
import com.example.home.R
import com.example.home.adapter.HomeFragViewPageAdapter
import com.example.home.databinding.ActHomeBinding
import com.example.home.databinding.ActMainHomeBinding
import com.google.android.material.navigation.NavigationBarView

/**
 * 首页
 */
class HomeAct : BaseActivity() {

    private lateinit var binding: ActMainHomeBinding
    private lateinit var adapter: HomeFragViewPageAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // 使用 DataBindingUtil 设置布局
        binding = DataBindingUtil.setContentView(this, R.layout.act_main_home)

        adapter = HomeFragViewPageAdapter(this)
        binding.homeMainVp.adapter = adapter
        binding.homeMainVp.isUserInputEnabled = false

        // 设置底部导航栏的点击事件
        binding.homeBottomNavigation.setOnItemSelectedListener(object :
            NavigationBarView.OnItemSelectedListener {
            override fun onNavigationItemSelected(item: MenuItem): Boolean {
                when (item.itemId) {
                    R.id.home_nav_home -> {
                        binding.homeMainVp.currentItem = 0
                        return true
                    }

                    R.id.home_nav_personal_center -> {
                        binding.homeMainVp.currentItem = 1
                        return true
                    }

                    else -> return false
                }
            }
        })



    }

}